package com.bxj.mybatis.generator.plugin;

import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.codegen.mybatis3.javamapper.elements.AbstractJavaMapperMethodGenerator;

import java.util.Set;
import java.util.TreeSet;

/**
 * Created by baixiujiang on 17/10/3.
 */
public class SelectSelectiveMethodGenerator extends AbstractJavaMapperMethodGenerator {
    @Override
    public void addInterfaceElements(Interface interfaze) {
        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        Method method = new Method();
        FullyQualifiedJavaType parameterType = new FullyQualifiedJavaType(
                introspectedTable.getBaseRecordType());

        method.setReturnType(new FullyQualifiedJavaType("List<" + parameterType + ">"));
        method.setVisibility(JavaVisibility.PUBLIC);
        method.setName(MybatisUtils.getTableProperties(introspectedTable, "selectSelectiveStatementId", "selectSelective"));

//        FullyQualifiedJavaType parameterType = introspectedTable.getRules()
//                .calculateAllFieldsClass();

        importedTypes.add(new FullyQualifiedJavaType("java.util.List"));
        importedTypes.add(parameterType);
        method.addParameter(new Parameter(parameterType, "object")); //$NON-NLS-1$

        context.getCommentGenerator().addGeneralMethodComment(method,
                introspectedTable);

//        addMapperAnnotations(interfaze, method);

//        if (context.getPlugins().clientInsertSelectiveMethodGenerated(
//                method, interfaze, introspectedTable)) {
        interfaze.addImportedTypes(importedTypes);
        interfaze.addMethod(method);
//        }
    }
}
